;=============================================================================
; Binary to BCD convertion.
; Make an assembly program to convert a BCD value into his correspondly binary.
; Admit that BCD is non-packed and the MSB nibble is zero. => positive
; Make the necessary allocations.
;=============================================================================
          absentry Entry

;Declaration of labels
          
RAM       EQU       $1000            ; RAM area
FLASH   EQU        $4000            ; Flash/Rom/Code area

RESET     EQU       $FFFE           ; interrupt vectors
CODE      EQU       FLASH          ; Code area

; Interrupt vectors

          org RESET
          dc.w      Entry

; Variable allocations

          org RAM

bcd       ds.w      3                   ; 0 < = bcd <= 255  three digits
bin        ds.w      1                  ; 255 fits into one byte

; Code
          org CODE
Entry:                                      ; Begin Main code
          ldaa      #0
          staa      bin

ReadCent:          
          ldaa      bcd+2               ; (AccA) <- (bcd+2) [affects ZF]
          beq       ReadDez         ; if (ZF == 1) ReadDez else...
          deca
          staa      bcd+2
          ldaa      bin
          adda      #100
          staa      bin
          bra       ReadCent
          
ReadDez:
          ldaa      bcd+1
          beq       ReadUni
          deca
          staa      bcd+1
          ldaa      bin
          adda      #10
          staa      bin
          bra       ReadDez
          
ReadUni:
          ldaa      bin
          adda      bcd
          staa      bin

          end          
                                        
          
                        
           
  